import React, { Component } from 'react'

import {getDatas} from '../../../utils/tools';

import RecomeCourseService from '../../../services/recomcourse'

import ListTitle from '../../../components/common/ListTitle';
import TableHead from '../../../components/common/TableHead'


import './index.scss'

const recomeCourseService = new RecomeCourseService();

export default class RecomeCourse extends Component {
    constructor(props){
        super(props);
        this.state={
            title:'推荐课程管理',
            recomCourseData:[]
        }
    }
    async getRecomCourseData(){
        const result = await recomeCourseService.getRecomCourseData(),
        errorCode = result.error_code,
        data = result.data,
        {history} = this.props;
        
        getDatas(errorCode,data,history,()=>{
          const {courseData,fieldData} = data;
          courseData.forEach((cItem,cIndex)=>{
              if(cItem.field === 0){
                  cItem.fieldTitle = '无分类'
              }
              fieldData.forEach((fItem,index)=>{
                  if(cItem.field === fItem.id){
                      cItem.fieldTitle = fItem.title
                  }
              })
          })
          this.setState({
            recomCourseData
          })
          
        })
       
    }
   
    render() {
        const {title,thData,courseData,fieldData} = this.state;
        return (
            <div className="list-container">
               <ListTitle title={title} onRefreshData={this.getRecomCourseData.bind(this)} ></ListTitle>
               <table className="list-table">
               {/* <TableHead thData={thData} ></TableHead>
              
               <TableBody courseData = {courseData} 
                fieldData={fieldData}
                onSelectChange={this.onSelectChange.bind(this)}
                onStatusClick = {this.onStatusClick.bind(this)}
               ></TableBody> */}
               </table>
            </div>
        )
    }
}
